import request from '@/utils/request'
import type { spuResponseData } from './model/spu'

// 枚举API
enum API {
    // SPU数据的地址
    SPULIST = '/admin/product/',
    // 全部品牌的地址
    TMURL = '/admin/product/baseTrademark/getTrademarkList',
    //全部销售属性接口
    ALLSALEATTR = '/admin/product/baseSaleAttrList',
    // 已有spu照片墙的地址
    IMAGELIST = '/admin/product/spuImageList/',
    // 获取spu已有销售属性
    HAVESALEATTR = '/admin/product/spuSaleAttrList/',
    // 添加SPU的地址
    ADDSPU = '/admin/product/saveSpuInfo',
    // 修改SPU的地址
    UPDATESPU = '/admin/product/updateSpuInfo',
    //平台属性
    ATTR = "/admin/product/attrInfoList/",
    // 添加SKU
    ADDSKU = '/admin/product/saveSkuInfo'
}

// 获取spu数据列表的接口
export const reqSpuList = (page: number, limit: number, id: number | string) => request.get<any, spuResponseData>(API.SPULIST + `${page}/${limit}/?category3Id=${id}`)

// 获取全部品牌的接口
export const reqAllTrademark = () => request.get(API.TMURL)

// 获取全部销售属性的接口
export const reqAllAttr = () => request.get(API.ALLSALEATTR)

// 获取已有spu照片墙的接口
export const reqImageList = (spuId: number) => request.get(API.IMAGELIST + spuId)

// 获取spu已有的销售属性接口
export const reqSaleAttr = (spuId: number) => request.get(API.HAVESALEATTR + spuId)




// 添加spu的接口
export const reqAddOrUpdateSpu = (data: any) => {
    // 有id修改，无id添加
    if (data.id) {
        return request.post(API.UPDATESPU, data)
    } else {
        return request.post(API.ADDSPU, data)
    }
}

//平台属性请求
export const reqAttrList = (category1Id: string | number, category2Id: string | number, category3Id: string | number) => request.get(API.ATTR + `${category1Id}/${category2Id}/${category3Id}`);

// 添加SKU的接口
export const reqAddSku = (data:any) =>request.post(API.ADDSKU,data)
